package com.mca.framework.completableFuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @Author: zhoupeng
 * @createTime: 2025年07月11日 09:25:44
 * @version: 1.0
 * @Description:
 * @copyright:
 */
public class RunAsyncDemo {
    public static void main(String[] args) {
        //指定线程池
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        //  CompletableFuture.runAsync  与  CompletableFuture.supplyAsync 区别
        // CompletableFuture.runAsync 执行异步任务，没有返回值
        // CompletableFuture.supplyAsync 执行异步任务，并返回结果return "异步任务结果";
        CompletableFuture.runAsync(()->{
            //子任务的业务
            try {
                TimeUnit.SECONDS.sleep(3);
                System.out.println(Thread.currentThread().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },executorService);
        //主任务
        System.out.println("main end");
        executorService.shutdown();
    }
}
